//package com.jida.tijian.handler;
//
//import com.jida.tijian.dto.ResponseObject;
//import com.jida.tijian.exception.TijianAPPException;
//import com.jida.tijian.exception.TijianAPPExceptionEnum;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//@ControllerAdvice
//public class GlobalExceptionHandler {
//
//
//    //只处理业务异常
//    @ExceptionHandler(TijianAPPException.class)
//    @ResponseBody//返回json格式数据给前端
//    public ResponseObject handleTijianAPPException(TijianAPPException e) {
//        e.printStackTrace();
//        System.out.println("异常信息：" + e.getStackTrace());
//
//        return new ResponseObject<>(e.getCode(), e.getMessage());
//
//    }
//
//    //处理所有异常
//    @ExceptionHandler(Exception.class)
//    @ResponseBody  //返回json格式数据给前端
//    public ResponseObject handleAllException(Exception e) {
//        e.printStackTrace();
//        System.out.println("异常信息：" + e.getStackTrace() + ",message:" + e.getMessage());
//        return new ResponseObject<>(TijianAPPExceptionEnum.SYSTEM_ERROR.getCode(), TijianAPPExceptionEnum.SYSTEM_ERROR.getMessage());
//
//    }
//
//
//}


package com.jida.tijian.handler;

import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.exception.TijianAPPExceptionEnum;
import com.jida.tijian.exception.TijianAPPException;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class GlobalExceptionHandler {


    //只处理业务异常
    @ExceptionHandler(TijianAPPException.class)
    @ResponseBody  //返回json格式数据给前端
    public ResponseObject handleTijianAppException(TijianAPPException e) {
        e.printStackTrace();
        System.out.println("异常信息：" + e.getStackTrace());

        return new ResponseObject<>(e.getCode(), e.getMessage());

    }

    //处理所有异常
    @ExceptionHandler(Exception.class)
    @ResponseBody  //返回json格式数据给前端
    public ResponseObject handleAllException(Exception e) {
        e.printStackTrace();
        System.out.println("异常信息：" + e.getStackTrace() + ",message:" + e.getMessage());
        return new ResponseObject<>(TijianAPPExceptionEnum.SYSTEM_ERROR.getCode(), TijianAPPExceptionEnum.SYSTEM_ERROR.getMessage());

    }


}
